<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--
  Created by IntelliJ IDEA.
  User: Admin
  Date: 2022-11-02
  Time: 13:54
  To change this template use File | Settings | File Templates.
--%>
<html>
<head>
    <meta charset="UTF-8">
    <title>生产工序审核</title>
    <style>
        input {
            border: white;
        }
    </style>
</head>
<body>

<form id="filebyidpc">
    <input type="hidden" name="productid" value="${param.productid}">
</form>
<form id="gongxushform">
    <input type="hidden" id="registertimetime" name="registertime">&nbsp;
    <input type="hidden" name="changetag" value="B002-0">
    <input type="hidden" name="designmodulechangetag" value="G003-0">
    <input type="hidden" name="id" value="${param.id}">
    <input type="hidden" name="designproceduretag" value="G001-0">
    <input type="hidden" name="checktag" id="checktagsw">
    <input type="hidden" name="designmoduletag" value="D002-0">
    <input type="hidden" name="designmodulechangetag" value="D003-0">
    <table class="TABLE_STYLE3">
        <tr height=20 class="TR_STYLE1">
            <td class="TD_HANDBOOK_STYLE1">您正在做的业务是：生产管理--产品生产工序设计--制定产品生产工序设计单</td>
        </tr>
    </table>
    <table align=center class="TABLE_STYLE6"style="margin-left:928px"  >
        <tr height=20 class="TR_STYLE1">
            <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right class="TD_STYLE8">
                <input type="radio" value="0" checked="checked" name="tongg">未通过
                <input type="radio" value="1" name="tongg">通过
                <input type="button" value="确定" class="btn btn-success" id="qdtjbtn">&nbsp;
            </td>
        </tr>
    </table>

    <div class="DIV_STYLE2">
        <table cellspacing=0 cellpadding=0 width=350 align=center border=0 bgcolor="#FFFFFF">
            <tbody>
            <tr>
                <td valign=bottom align=center class="TABLE_STYLE6" rowspan=2>
                    <table cellspacing=0 cellpadding=0 width="800px" border=0
                           style="BORDER-RIGHT: #333333 1px solid; BORDER-TOP: #333333 1px solid; BORDER-LEFT: #333333 1px solid; BORDER-BOTTOM: #333333 1px solid;">
                        <tbody>
                        <tr>
                            <td colspan="4" height="10">
                                <table width="850px" style="height: 400px">
                                    <tr>
                                        <td>
                                            <table align=center class="TABLE_STYLE4">
                                                <tr height=20 class="TR_STYLE1">
                                                    <td align=center height=5 class="TD_STYLE5">&nbsp;</td>
                                                </tr>
                                            </table>
                                            <table align=center class="TABLE_STYLE4">
                                                <tr height=20 class="TR_STYLE1">
                                                    <td align=center height=5 class="TD_STYLE5"><font size="4"><b>生产工序设计单</b></font>
                                                    </td>
                                                </tr>
                                            </table>
                                            <table align=center class="TABLE_STYLE4">
                                                <tr height=20 class="TR_STYLE1">
                                                    <td align=center height=5 class="TD_STYLE5">&nbsp;</td>
                                                </tr>
                                            </table>
                                            <table align=center class="TABLE_STYLE4">
                                                <tr height=20 class="TR_STYLE1">
                                                    <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right
                                                        class="TD_STYLE8" width="20%">设计单编号 ：
                                                    </td>
                                                    <td bordercolor=#DEDBD6 align=left class="TD_STYLE2" width="40%">
                                                        <input type="text" name="designid" id="designiddp" readonly>&nbsp;
                                                    </td>
                                                    <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right
                                                        class="TD_STYLE8" width="10%">设计人&nbsp;&nbsp;：
                                                    </td>

                                                    <td bordercolor=#DEDBD6 align=left class="TD_STYLE2" width="40%">
                                                        <input type="text" name="designer" id="designerdp">&nbsp;
                                                    </td>
                                                </tr>
                                                <tr height=20 class="TR_STYLE1">
                                                    <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right
                                                        class="TD_STYLE8" width="10%">产品名称：
                                                    </td>
                                                    <td bordercolor=#DEDBD6 align=left class="TD_STYLE2" width="40%">
                                                        <input type="text" name="productname" id="productnamedp"
                                                               readonly> &nbsp;
                                                    </td>
                                                    <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right
                                                        class="TD_STYLE8" width="10%">产品编号：
                                                    </td>
                                                    <td bordercolor=#DEDBD6 align=left class="TD_STYLE2" width="40%">
                                                        <input type="text" name="productid" id="productiddp" readonly>&nbsp;
                                                    </td>
                                                </tr>
                                            </table>

                                            <table id="shengchangongxulisting" align=center class="TABLE_STYLE4">
                                            </table>


                                            <table align=center class="TABLE_STYLE4">
                                                <tr height=20 class="TR_STYLE1">
                                                    <td align=center height=5 class="TD_STYLE5">&nbsp;</td>
                                                </tr>
                                            </table>
                                            <TABLE align=center class="TABLE_STYLE4">
                                                <tr height=20 class="TR_STYLE1">
                                                    <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right
                                                        class="TD_STYLE8" width="15%">工时总成本：
                                                    </td>
                                                    <td bordercolor=#DEDBD6 align=left class="TD_STYLE2" width="40%">
                                                        <input type="text" name="costpricesum" id="costpricesumdp"
                                                               readonly>&nbsp;
                                                    </td>
                                                </tr>
                                                <tr height=20 class="TR_STYLE1">
                                                    <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right
                                                        class="TD_STYLE8" width="10%">审核人&nbsp;&nbsp;：
                                                    </td>
                                                    <td bordercolor=#DEDBD6 align=left class="TD_STYLE2" width="40%">
                                                        <input type="text" name="checker" value="${username}" id="checkerdp" readonly>&nbsp;
                                                    </td>
                                                    <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right
                                                        class="TD_STYLE8" width="15%">审核时间：
                                                    </td>
                                                    <td bordercolor=#DEDBD6 align=left class="TD_STYLE2" width="40%">
                                                        <input type="text" id="checktimedp" name="checktime" readonly>&nbsp;
                                                    </td>
                                                </tr>
                                                <tr height=20 class="TR_STYLE1">
                                                    <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right
                                                        class="TD_STYLE8" width="10%">设计要求：
                                                    </td>
                                                    <td bordercolor=#DEDBD6 align=left class="TD_STYLE2" width="89%"
                                                        colspan="3"><textarea name="proceduredescribe"
                                                                              id="proceduredescribedp"></textarea>&nbsp;
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3" nowrap width="56">
                            </td>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3" nowrap height="100"></td>
                            <td></td>
                        </tr>

                        <tr valign="bottom">
                            <td colspan="4" nowrap align="center"></td>
                        </tr>
                        </td>
                        <tr>
                            <td colspan="4" nowrap align="right"></td>
                        </tr>
                        </tbody>
                    </table>
                </td>
                <td width=1 bgcolor=#ffffff height=2></td>
                <td width=1 bgcolor=#ffffff height=2></td>
                <td width=1 bgcolor=#ffffff height=2></td>
            </tr>
            <tr>
                <td width=1 bgcolor=#333333 height=120></td>
                <td width=1 bgcolor=#666666 height=120></td>
                <td width=1 bgcolor=#999999 height=120></td>
            </tr>
            <tr valign=top align=right>
                <td colspan=4>
                    <table cellspacing=0 cellpadding=0 align=center class="TABLE_STYLE6" border=0>
                        <tbody>
                        <tr>
                            <td bgcolor=#333333 height=1></td>
                        </tr>
                        <tr>
                            <td bgcolor=#666666 height=1></td>
                        </tr>
                        <tr>
                            <td bgcolor=#999999 height=1></td>
                        </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr valign=center align=right>
                <td colspan=4></td>
            </tr>
            </tbody>
        </table>
    </div>
</form>

<script>
    $(function () {
        var designid = '${param.id}'
        $.get("querydesignProcedure2.action/" + designid, function (data) {
            //$("#checkerdp").val(data.checker)
            $("#designerdp").val(data.designer)
            $("#productnamedp").val(data.productname)
            $("#productiddp").val(data.productid)
             $("#registertimetime").val(data.registertime)
            $("#designiddp").val(data.designid)
            $("#proceduredescribedp").val(data.proceduredescribe)
            var parentid = data.id
            $("#shengchangongxulisting").bootstrapTable({
                url: "querydesignProcedureDetails.action/"+parentid,
                method: 'post',                      //请求方式（*）
                contentType: "application/x-www-form-urlencoded",
                // toolbar: '#toolbar',              //工具按钮用哪个容器
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                sortable: true,                     //是否启用排序
                sortOrder: "asc",                   //排序方式
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                      //初始化加载第一页，默认第一页,并记录
                pageSize: 5,                     //每页的记录行数（*）
                pageList: [5, 10, 25, 50, 100],        //可供选择的每页的行数（*）
                search: false,                      //是否显示表格搜索
                strictSearch: true,
                showColumns: true,                  //是否显示所有的列（选择显示的列）
                showRefresh: true,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                // height: 500,                      //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "id",                     //每一行的唯一标识，一般为主键列
                showToggle: true,                   //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,                  //是否显示父子表
               showFooter: true,
                //得到查询的参数
                queryParams: function (params) {
                    //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    var temp = {
                        pagesize: params.limit,                         //页面大小
                        pagenum: (params.offset / params.limit) + 1,   //页码
                        sort: params.sort,      //排序列名
                        sortOrder: params.order, //排位命令（desc，asc）
                    };
                    return temp;
                },
                columns: [
                    {
                        field: 'id',
                        title: '序号',
                        footerFormatter: function (value) {
                        return "工时总成本";
                        }
                    },
                    {
                        field: 'procedurename',
                        title: '工序名称'
                        // footerFormatter: function (value) {
                        // return "工时总成本";
                        // }
                    }
                    , {
                        field: 'procedureid',
                        title: '工序编号'
                    }, {
                        field: 'proceduredescribe',
                        title: '描述'
                    }
                    , {
                        field: 'labourhouramount',
                        title: '工时数',
                        formatter: function (value, row, index) {
                            return "<input type='text' value='" + value + "' onchange='changenum111(this)' >";
                        }
                    },
                    {
                        field: 'amountunit',
                        title: '工时单位',
                        formatter: function (value, row, index) {
                            if (value == "" || value == null) {
                                return "<label class='label leabel-success'>小时</label>";
                            }

                        }
                    },
                    {
                        field: 'costprice',
                        title: '单位工时成本',
                        formatter: function (value, row, index) {
                            return "<input type='text' value='" + value + "' onchange='changenum222(this)' >";
                        }

                    },
                    {
                        field: 'subtotal',
                        title: '工时成本小计（元）',
                        formatter: function (value, row, index) {
                            return "<input type='text' readonly  value='" + value + "' >";
                        },
                        footerFormatter:function (value) {
                            var count=0;
                        for(var i in value){
                            count+=value[i].subtotal
                        }
                        $("#costpricesumdp").val(count)
                        return count;
                        }
                    }]
            });

        }, "json")

        // 获取当前时间
        var time = getTime();
        $("#checktimedp").val(time);

    })



    //输入数字，将数字更新到1表格中changenum111
    function changenum111(obj1) {
        //获取表格当前所有数据
        var arr2 = $("#shengchangongxulisting").bootstrapTable("getData");
        //获取当前输入的值
        var labourhouramount = $(obj1).val();
        //获取当前操作行的id
        var id = $(obj1).parent().parent().find("td:eq(2)").text();
        //获取当前操作行的id
        var shu1 = $(obj1).parent().parent().find("input:eq(0)").val();

        var reg = /^[0-9]*$/
        if (!reg.test(shu1)) {
            alert("请输入数字")
            $(obj).parent().parent().find("input:eq(0)").val("1");
            return
        }

        var shu2 = $(obj1).parent().parent().find("input:eq(1)").val();
        var reg2 = /^[0-9]*$/
        if (!reg2.test(shu2)) {
            alert("请输入数字")
            $(obj).parent().parent().find("input:eq(1)").val("1");
            return
        }

       var  zong1= Number(shu1) * Number(shu2)

        //循环表格数据  和当前行id比较  相等  跟新labourhouramount
        $(arr2).each(function (index, item) {
            if (item.procedureid == id) {
                item.labourhouramount = labourhouramount;
                item.subtotal = zong1;
            }
        })
        //数据加载到表格
        $("#shengchangongxulisting").bootstrapTable("load", arr2);
    }


    //changenum222
    function changenum222(obj) {
        //获取表格当前所有数据
        var arr2 = $("#shengchangongxulisting").bootstrapTable("getData");
        //获取当前输入的值
        var costprice = $(obj).val();
        //获取当前操作行的id
        var id = $(obj).parent().parent().find("td:eq(2)").text();
        //获取当前操作行的id
        var shu1 = $(obj).parent().parent().find("input:eq(0)").val();
        var reg = /^[0-9]*$/
        if (!reg.test(shu1)) {
            alert("请输入数字")
            $(obj).parent().parent().find("input:eq(0)").val("1");
            return
        }

        var shu2 = $(obj).parent().parent().find("input:eq(1)").val();

        var reg2 = /^[0-9]*$/
        if (!reg2.test(shu2)) {
            alert("请输入数字")
            $(obj).parent().parent().find("input:eq(1)").val("1");
            return
        }
       var  zong = Number(shu1) * Number(shu2)

        //循环表格数据  和当前行id比较  相等  costPrice
        $(arr2).each(function (index, item) {
            if (item.procedureid == id) {
                item.costprice = costprice;
                item.subtotal = zong;
            }
        })
        //数据加载到表格
        $("#shengchangongxulisting").bootstrapTable("load", arr2);
    }


        //保存
        $("#qdtjbtn").click(function () {
            //  通過
            if ($(":radio:checked").val() == 1) {
                $("#checktagsw").val("S001-1")
                //確定
                var arr = $("#gongxushform").serializeArray();
                console.log(arr)
                var gongxushow2 = {};
                $(arr).each(function (index, item) {
                    gongxushow2[item.name] = item.value;
                })

                //从表格获取组成明细数据
                var arr2 = $("#shengchangongxulisting").bootstrapTable("getData");
                //将明细数据 存入和实体类中同名的属性上
                gongxushow2["detailss"] = arr2;
                $.ajax({
                    url: "updateesignProcedureshow.action",
                    type: "put",
                    data: JSON.stringify(gongxushow2),
                    contentType: "application/json",
                    dataType: "json",
                    success: function (data) {
                        alert(data.msg)
                    }
               })
            }
            else if($(":radio:checked").val() == 0){
               $("#checktagsw").val("S001-3")
                var arr1 = $("#gongxushform").serializeArray();
                var gongxushow21 = {};
                $(arr1).each(function (index, item) {
                    gongxushow21[item.name] = item.value;
                })
                var arr21 = $("#shengchangongxulisting").bootstrapTable("getData");
                //将明细数据 存入和实体类中同名的属性上
                gongxushow21["detailss"] = arr21;
                $.ajax({
                    url: "updateesignProcedureshowchongfu.action",
                    type: "put",
                    data: JSON.stringify(gongxushow21),
                    contentType: "application/json",
                    dataType: "json",
                    success: function (data) {
                        if(data.cm==1) {
                            var dataobj = $("#filebyidpc").serializeArray();
                            var obj = {};
                            $(dataobj).each(function (index, item) {
                                obj[item.name] = item.value;
                            })
                            $.ajax({
                                url: "updatemcppojo2.action",
                                type: "put",
                                data: JSON.stringify(obj),
                                contentType: "application/json",
                                dataType: "json",
                                success: function (data) {
                                }
                            })
                        }
                    }
                })
                $("#checktagsw").val("S001-2")
                //获取物料组成数据
                var arr = $("#gongxushform").serializeArray();
                console.log(arr)
                var gongxushow3 = {};
                $(arr).each(function (index, item) {
                    gongxushow3[item.name] = item.value;
                })
                //从表格获取组成明细数据
                var arr2 = $("#shengchangongxulisting").bootstrapTable("getData");
                //将明细数据 存入和实体类中同名的属性上
                gongxushow3["detailss"] = arr2;
                $.ajax({
                    url: "readddesignProcedure.action",
                    type: "put",
                    data: JSON.stringify(gongxushow3),
                    contentType: "application/json",
                    dataType: "json",
                    success: function (data) {
                        alert(data.msg)
                    }
                })
            }
        })


    // 获取当前日期时间方法
    function getTime() {
        var date = new Date();
        var y = date.getFullYear();
        var M = date.getMonth() + 1;
        M = M < 10 ? ('0' + M) : M;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d
        var h = date.getHours();
        var m = date.getMinutes();
        var s = date.getSeconds();
        const time = y + '-' + M + '-' + d + " " + h + ":" + m + ":" + s;
        return time;
    }

</script>

</div>
</body>
</html>
